<?php
/**
 * @author Demianchuk Dmitro
 * @email d.demianchuk@gmail.com
 * @date 30.12.11
 * @version 1.0
 * @package application.components
 */
class AAdminMenu extends CWidget
{
	public function run(){
		$modules = Yii::app()->modules;
		$modules = $modules['adminArea']['modules'];
		$menu = array();
		foreach($modules AS $k=>$v){
			Yii::import('application.modules.adminArea.modules.'.$k.'.'.$k.'Module');
			$moduleName = $k.'Module';
			$menu[] = $moduleName::getMenuConfig();
		}
		echo $this->generateMenu($menu,'');
	}

	private function generateMenu($menuConfig,$menuString){
		$menuString .= '<ul>';
		foreach($menuConfig as $k=>$v){
			$menuString .= '<li>';
			if(!isset($v['sub'])){
				$menuString .= '<a href="'.$v['url'].'">'.$v['name'].'</a>';
			}else{
				$menuString .= '<span>'.$v['name'].'</span>';
				$menuString = $this->generateMenu($v['sub'],$menuString);
			}
			$menuString .= '</li>';
		}
		$menuString .= '</ul>';
		return $menuString;
	}
}
